
</html>
		<header>
			<meta charset="UTF-8">
		</header>
		<body>

		<textarea id="response" style="width:300px;height: 300px;border: 1px solid black;"></textarea>
		<input type="text" id="inputstr"/>

		<button onclick="send">发送</button>

		<script type="text/javascript">
			var websocket = null;
			//建立websocket请求
			function buildWS(){
				if ('WebSocket' in window) {
					websocket = new WebSocket("ws://127.0.0.1:6666/hello");
					// 建立连接
					websocket.onopen = function(event){
						document.getElementById("inputstr").innerText = "建立连接";
					}

					//接收到推送消息
					websocket.onmessage = function(event){
						//window.parent.successMsg("服务端推送消息");
						document.getElementById("inputstr").innerText = event.data;

					}
					websocket.onclose = function () {
						document.getElementById("inputstr").innerText = "断开连接";
					}
				} else {
					alert('不支持websocket')
					return false;
				}
			}

			// 发送数据
			function send(){
				websocket.send(document.getElementById("inputstr").value);
			}

			window.onload = function () {
				buildWS();
			}
		</script>
	</body>
</html>
